package com.easytopit.demo.spring.mvc.httpclient;

import java.io.IOException;import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class HttpClientGetDemo {

	public static void main(String[] args) throws IOException {
		OkHttpClient client = new OkHttpClient();
		// 地址
		Request request = new Request.Builder().url("http://api.map.baidu.com/location/ip?ak=AsT6khHyTR2EfKwq2OFWf30NGQCLrLM1").build();
		Response response = client.newCall(request).execute();
		System.out.println(response.code());
		
		// 数据
		String string = response.body().string();
		System.out.println(string);
		
		// 
//		Map map = JSON.parseObject(string, Map.class);
//		System.out.println(map);
		
		JSONObject json = JSON.parseObject(string);
		String city = json.getJSONObject("content").getJSONObject("address_detail").getString("city");
		
		// 天气
		// 地址
		request = new Request.Builder().url("http://wthrcdn.etouch.cn/weather_mini?city="+city).build();
		response = client.newCall(request).execute();
		System.out.println(response.code());
		
		// 数据
		string = response.body().string();
		System.out.println(string);
		
		// 提供API
		// 调用API
	}
	
}
